<template>
	<view>
		<view class="uni-header">
			<view class="uni-group">
				<view class="uni-title">{{title}}</view>
			</view>
		</view>
		<view class="uni-container">
			<uni-forms ref="form" validateTrigger="bind" :rules="rules">
				<uni-forms-item label="标题" name="title" labelWidth="85">
					<input class="uni-input-border" type="text" placeholder="标题" v-model="item.title"/>
				</uni-forms-item>

				<uni-forms-item label="内容" name="content" labelWidth="85">
					<textarea placeholder="内容" class="content" v-model="item.content"/>
					</uni-forms-item>
				
				<view class="uni-padding-wrap">
					<view class="uni-title">类型</view>
					<radio-group @change="radioChange">
						<label class="radio"><radio value="zhuce" :checked="item['type']=='zhuce'" />注册</label>
						<label class="radio"><radio value="youxi" :checked="item['type']=='youxi'"/>游戏</label>
						<label class="radio"><radio value="tixian" :checked="item['type']=='tixian'"/>提现</label>
					</radio-group>
				</view>
				
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">{{item['caozuo']=='remove'?'删除':'保存'}}</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import config from '@/admin.config.js'
	export default {
		data() {
			return {
				isLoading: false,
				showPassword: true,
				showPasswordAgain: true,
				errorMessage: '',
				rules: {
					title: {
						rules: [{
							required: true,
							errorMessage: '请输入标题'
						}]
					},
					content: {
						rules: [{
								required: true,
								errorMessage: '请输入内容'
							},
						]
					},
				},
			}
		},
		props: ['item',"title"],
		methods: {
			...mapMutations({
				removeToken(commit) {
					commit('user/REMOVE_TOKEN')
				}
			}),
			
			submitForm(){
				
			},
			radioChange(evt){
				this.item['type'] = evt.target.value
				console.log(this.item)
			},
			save() {
				let self = this
				this.isLoading = true
				console.log(this.item)
				
				uni.showLoading({
					title: '处理中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/changehelp",
						data:this.item
					}
				}).then((res) => {
					console.log(res, "res--------------")
					this.isLoading = false
					uni.hideLoading();
					let showTitle = ''
					switch (this.item['caozuo']){
						case 'add':
							showTitle = '新增成功'
							break;
						case 'update':
							showTitle = '更新成功'
							break;
						case 'remove':
							showTitle = '删除成功'
							break;
						default:
							break;
					}
					uni.showToast({
						title: showTitle,
						icon: 'none',
						duration: 2000
					})
					this.$emit('closeHelpPopup')
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
				// this.$request('admin/changehelp', this.item).then(res => {
				// 	this.isLoading = false
				// 	console.log(res)
				// 	if (res.code && res.code != 0) {
				// 		uni.showToast({
				// 			title: res.result.message,
				// 			icon: 'none',
				// 		});
				// 		return
				// 	}
				// 	if (res.errcode && res.errcode != 0) {
				// 		uni.showToast({
				// 			title: res.errmsg,
				// 			icon: 'none',
				// 		});
				// 		return
				// 	}
				// 	uni.showToast({
				// 		title: "操作成功",
				// 		icon: 'none',
				// 		duration: 2000
				// 	})
				// 	this.$emit('closeHelpPopup')
				// }).catch(res => {

				// }).finally(err => {
				// 	this.isLoading = false
				// })
			},
		}
	}
</script>


<style>
	page {
		background-color: #fff;
		padding: 20px;
	}

	.uni-forms {
		width: 100%;
	}

	.login-button-width {
		width: 184px;
	}
	.content{
		border: 1px solid #e5e5e5;
		width: 100%;
		padding: 5px 10px;
		box-sizing: border-box;
	}
	.radio{
		margin-right: 25px;
	}
	.uni-title{
		font-size: 14px;
	}
</style>
